#include<iostream>
#include<vector>
using namespace std;
class Solution
{
    // 扔进去AC了他
public:

    void rotate(vector<int>& nums, int k)
    {
        int n = nums.size();
        k=k%n;
        if (k%n==0)
           return ;
        int b[k];
        int j=0;
        for(int i=n-k;i<n;i++)
        {    b[j]=nums[i];
            j++;
        }
        for(int i=n-1;i>=k;i--)
        {
            nums[i]=nums[i-k];
        }

        for(int i=0;i<k;i++)
        {
            nums[i]=b[i];

        }
    };


    void reverse(vector<int>& nums, int s,int e)
    {
      int temp;
      for(int i=s;i< (e+s)/2;i++)
      {

      temp = nums[e-i-1+s];
      nums[e-i-1+s] = nums[i];
      nums[i]= temp;
      }

    }

    void rotate2(vector<int>& nums, int k)
    {
        int n = nums.size();
        k=k%n;
        reverse(nums,0,n);
        reverse(nums,0,k);
        reverse(nums,k,n);
    }




};


int main() {
    int a[] = {1,2,3,4,5,6,7};

    int k = 3;

    int n = sizeof(a)/sizeof(a[0]);


    vector<int> arr(a,a+n);
    Solution().rotate2(arr,k);
    for(int i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<endl;
    return 0;
}